<?php 
class Flinkcontroller extends AuthController{
	private $model;
	/**
	 * 初始化
	 */
	 public function __init(){
	 	parent::__init();
		//K就是调用扩展模型Common/Model文件夹里面
		$this->model=K('Flink');
	 }
	
	/**
	 * 展示
	 */
	public function index(){
		$data=$this->model->all();
		$this->assign('data',$data);
//		p($data);die;
		
		$this->display();
		
		
		
	}
	
	
	/**
	 * 添加
	 */
	public function addlink(){
		if(IS_POST){
			if(!$this->model->addlink()) $this->error($this->model->error);
			$this->success('添加成功');
		}
		
		$this->display();
	}
	/**
	 * 删除
	 */
	 public function del(){
	 	$fid=Q('get.fid');
		$this->model->where("fid={$fid}")->delete();
		$this->success('删除成功');
	 }
	/**
	 * 编辑
	 */
	public function edit(){
		if(IS_POST){
			if(!$this->model->editlink()) $this->error($this->model->error);
			$this->success('编辑成功',U('index'));
		}
		//获得旧数据
		$fid=Q('get.fid');
		$oldData=$this->model->where("fid={$fid}")->all();
	    $this->assign('oldData',$oldData);
//		p($oldData);die;
		$this->display();
	}
	
	
	/**
	 * 上传logo
	 */
	     public function upload(){
	        $upload = new Upload('Upload/logo/' . date('y/m'));
	        $file = $upload->upload();
	        if (empty($file)) {
	        		//相当于 echo json_encode('上传失败');exit;
	            $this->ajax('上传失败');
	        } else {
	        		/** $file内部就是以下这个数组
	        		$file = array(
	        			0 => array(
						'path' => 'Upload/Content/15/8/123981239172.jpg'	,
						'url' => 'http://localhost/cms_edu/Upload/Content/15/8/123981239172.jpg',
					 	'image' => 1
					),
				);**/
	        		//上传成功，把上传好的信息返给js
	            $data = $file[0];
	            $this->ajax($data);
	        }
	    }
	
	
}


 ?>